﻿<?xml version="1.0" encoding="utf-8" ?>
<Recipe Name="GenerateViewClasses" Bound="false"
        xmlns="http://schemas.microsoft.com/pag/gax-core"
        xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="Common/CommonTypeAliases.xml"
				xpointer="xmlns(gax=http://schemas.microsoft.com/pag/gax-core) xpointer(/gax:Types)" />
  <Caption>Add new View with ViewModel</Caption>
  <Description>Generates a new View with associated ViewModel class.</Description>
  <HostData>
    <CommandBar Menu="PRISMProject"/>
  </HostData>
  <Arguments>
    <!--Arguments for the UI -->
    <Argument Name="ViewName" Required="true">
      <ValueProvider Type="Evaluator" Expression="View1" />
    </Argument>
    <Argument Name="ViewModelName" Required="true">
      <ValueProvider Type="Evaluator" Expression="ViewModel1" />
    </Argument>
    <Argument Name="ViewModelTestClassName" Required="true">
      <ValueProvider Type="Evaluator" Expression="ViewModelFixture1" />
    </Argument>
    <Argument Name="ViewModelInterfaceName" Required="true">
      <ValueProvider Type="Evaluator" Expression="IViewModel1" />
    </Argument>
    <Argument Name="GenerateCodeTemplates" Required="true" Type="System.Boolean">
      <ValueProvider Type="Evaluator" Expression="True" />
    </Argument>

    <!--Target file names-->
    <Argument Name="ViewXamlTargetFile">
      <ValueProvider Type="Evaluator" Expression="$(ViewName).xaml">
        <MonitorArgument Name="ViewName" />
      </ValueProvider>
    </Argument>
    <Argument Name="ViewXamlCsTargetFile">
      <ValueProvider Type="Evaluator" Expression="$(ViewName).xaml.cs">
        <MonitorArgument Name="ViewName" />
      </ValueProvider>
    </Argument>
    <Argument Name="ViewModelTargetFile">
      <ValueProvider Type="Evaluator" Expression="$(ViewModelName).cs">
        <MonitorArgument Name="ViewModelName" />
      </ValueProvider>
    </Argument>
    <Argument Name="ViewModelTestClassTargetFile">
      <ValueProvider Type="Evaluator" Expression="$(ViewModelTestClassName).cs">
        <MonitorArgument Name="ViewModelTestClassName" />
      </ValueProvider>
    </Argument>
    <Argument Name="ViewModelInterfaceTargetFile">
      <ValueProvider Type="Evaluator" Expression="$(ViewModelInterfaceName).cs">
        <MonitorArgument Name="ViewModelInterfaceName" />
      </ValueProvider>
    </Argument>

    <!--The following arguments are used to recreate the Views and ViewModedels folders in the case they do not exist-->
    <Argument Name="CreateFolders" Required="true" Type="System.Boolean">
      <ValueProvider Type="Evaluator" Expression="true" />
    </Argument>
    <Argument Name="ViewsFolderName" Required="true">
      <ValueProvider Type="Evaluator" Expression="Views" />
    </Argument>
    <Argument Name="ViewModelsFolderName" Required="true">
      <ValueProvider Type="Evaluator" Expression="ViewModels" />
    </Argument>

    <Argument Name="ModuleName" Type="System.String">
      <ValueProvider Type="Evaluator" Expression="$(ModuleProject.Name)"></ValueProvider>
    </Argument>
    <Argument Name="ModuleNamespace">
      <ValueProvider Type="Evaluator" Expression="$(ModuleName)">
        <MonitorArgument Name="ModuleName"/>
      </ValueProvider>
    </Argument>

    <!--Retrieves Module project instance-->
    <Argument Name="ModuleProject" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <Converter Type="ProjectConverter" />
      <ValueProvider Type="FirstSelectedProjectValueProvider" />
    </Argument>

    <!--Retrieves Module Test project instance-->
    <Argument Name="TestProjectName" Type="System.String">
      <ValueProvider Type="Evaluator" Expression="$(ModuleName).Tests">
        <MonitorArgument Name="ModuleName"/>
      </ValueProvider>
    </Argument>
    <Argument Name="ModuleTestProject" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Required="false">
      <ValueProvider Type="ProjectByNameExpressionProvider" NameExpression="$(TestProjectName)" Stage="OnBeforeActions">
        <MonitorArgument Name="TestProjectName"/>
      </ValueProvider>
    </Argument>

    <!--Retrieves the Infrastrucuture project-->
    <Argument Name="InfrastructureProjectGuid" Type="System.String">
      <ValueProvider Type="GlobalValueProvider" Key="InfrastructureProjectGuid" />
    </Argument>
    <Argument Name="InfrastructureProject" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <ValueProvider Type="GetProjectFromGuidValueProvider" FromArgument="InfrastructureProjectGuid">
        <MonitorArgument Name="InfrastructureProjectGuid"/>
      </ValueProvider>
    </Argument>
    <Argument Name="InfrastructureProjectName" Type="System.String">
      <ValueProvider Type="Evaluator" Expression="$(InfrastructureProject.Name)" />
    </Argument>


    <!--Checks if the test project exists-->
    <Argument Name="TestProjectExists" Type="System.Boolean">
      <ValueProvider Type="IsValidExpressionProvider" ValueExpression="$(ModuleTestProject)" Stage="OnBeforeActions"/>
    </Argument>

    <!--Retrieve the project items collection where to add the new generated items-->
    <Argument Name="TargetProjectItems" Type="EnvDTE.ProjectItems, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <ValueProvider Type="TargetItemsCollectionProvider" />
    </Argument>

  </Arguments>
  <GatheringServiceData>
    <Wizard xmlns="http://schemas.microsoft.com/pag/gax-wizards" SchemaVersion="1.0" Help="ms-help://MS.VSCC.v90/MS.VSIPCC.v90/ms.practices.scsf.2008apr/SCSF/html/03-01-020-How_to_Create_a_Business_Module.htm">
      <Pages>
        <Page Type="PrismFactory.SoftwareFactory.CustomWizardPages.GenerateViewClasses.GenerateViewClassesPage, PrismGuidancePackage" Height="700" Width="400">
          <Title>Generate Model class</Title>
          <LinkTitle>Generate Model class</LinkTitle>
        </Page>
      </Pages>
    </Wizard>
  </GatheringServiceData>
  <Actions>

    <!--Ensures proper folders-->
    <Action Name="EnsureViewsFolder" Type="CreateProjectFolderAction">
      <Input Name="CreateFolder" RecipeArgument="CreateFolders" />
      <Input Name="FolderName" RecipeArgument="ViewsFolderName" />
      <Input Name="TargetCollection" RecipeArgument="TargetProjectItems" />
      <Output Name="FolderCollection"/>
    </Action>
    <Action Name="EnsureViewModelsFolder" Type="CreateProjectFolderAction">
      <Input Name="CreateFolder" RecipeArgument="CreateFolders" />
      <Input Name="FolderName" RecipeArgument="ViewModelsFolderName" />
      <Input Name="TargetCollection" RecipeArgument="TargetProjectItems" />
      <Output Name="FolderCollection"/>
    </Action>

    <!--Generates and add the View class to the solution-->
    <Action Name="GenerateXaml" Type="TextTemplateAction" Template="Items\View\View.xaml.tt">
      <Input Name="ClassName" RecipeArgument="ViewName" />
      <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace" />
      <Input Name="GenerateCodeTemplates" RecipeArgument="GenerateCodeTemplates"/>
      <Output Name="Content" />
    </Action>
    <Action Name="GenerateXamlCs" Type="TextTemplateAction" Template="Items\View\View.xaml.cs.tt">
      <Input Name="ClassName" RecipeArgument="ViewName" />
      <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace" />
      <Input Name="GenerateCodeTemplates" RecipeArgument="GenerateCodeTemplates"/>
      <Output Name="Content" />
    </Action>
    <Action Name="AddXaml" Type="AddItemFromStringToProjectItemsAction" Open="false" Overwrite="false">
      <Input Name="Content" ActionOutput="GenerateXaml.Content" />
      <Input Name="TargetFileName" RecipeArgument="ViewXamlTargetFile" />
      <Input Name="TargetCollection"  ActionOutput="EnsureViewsFolder.FolderCollection" />
      <Output Name="CreatedProjectItems" />
    </Action>
    <Action Name="AddXamlCs" Type="AddItemFromStringToProjectItemsAction" Open="false" Overwrite="false">
      <Input Name="Content" ActionOutput="GenerateXamlCs.Content" />
      <Input Name="TargetFileName" RecipeArgument="ViewXamlCsTargetFile" />
      <Input Name="TargetCollection"  ActionOutput="EnsureViewsFolder.FolderCollection" />
      <Output Name="CreatedProjectItems" />
    </Action>

    <!--Generates and add the ViewModel class to the solution-->
    <Action Name="GenerateViewModel" Type="TextTemplateAction" Template="Items\View\ViewModel.cs.tt">
      <Input Name="ClassName" RecipeArgument="ViewModelName" />
      <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace" />
      <Input Name="InterfaceName" RecipeArgument="ViewModelInterfaceName" />
      <Input Name="InfrastructureProjectName" RecipeArgument="InfrastructureProjectName" />
      <Input Name="GenerateCodeTemplates" RecipeArgument="GenerateCodeTemplates"/>
      <Output Name="Content" />
    </Action>
    <Action Name="AddViewModelClass" Type="AddItemFromStringToProjectItemsAction" Open="true" Overwrite="false">
      <Input Name="Content" ActionOutput="GenerateViewModel.Content" />
      <Input Name="TargetFileName" RecipeArgument="ViewModelTargetFile" />
      <Input Name="TargetCollection"  ActionOutput="EnsureViewModelsFolder.FolderCollection" />
      <Output Name="CreatedProjectItems" />
    </Action>

    <!--Generates and add the ViewModel interface to the solution-->
    <Action Name="GenerateViewModelInterface" Type="TextTemplateAction" Template="Items\View\IViewModel.cs.tt">
      <Input Name="InterfaceName" RecipeArgument="ViewModelInterfaceName" />
      <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace" />
      <Input Name="GenerateCodeTemplates" RecipeArgument="GenerateCodeTemplates"/>
      <Output Name="Content" />
    </Action>
    <Action Name="AddViewModelInterface" Type="AddItemFromStringToProjectItemsAction" Open="true" Overwrite="false">
      <Input Name="Content" ActionOutput="GenerateViewModelInterface.Content" />
      <Input Name="TargetFileName" RecipeArgument="ViewModelInterfaceTargetFile" />
      <Input Name="TargetCollection"  ActionOutput="EnsureViewModelsFolder.FolderCollection" />
      <Output Name="CreatedProjectItems" />
    </Action>

    <!--Generates and adds the ViewModel test class to the solution-->
    <Action Name="GenerateViewModelTestClass" Type="TextTemplateAction" Template="Items\View\ViewModelFixture.cs.tt">
      <Input Name="ClassName" RecipeArgument="ViewModelTestClassName" />
      <Input Name="ViewModelClassName" RecipeArgument="ViewModelName" />
      <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace" />
      <Output Name="Content" />
    </Action>
    <Action Condition="$(TestProjectExists)" Name="AddViewModelTestClass" Type="AddItemFromStringToProjectItemByNameAction" Open="true" Overwrite="false">
      <Input Name="Content" ActionOutput="GenerateViewModelTestClass.Content" />
      <Input Name="ItemName" RecipeArgument="ViewModelsFolderName"/>
      <Input Name="TargetFileName" RecipeArgument="ViewModelTestClassTargetFile"/>
      <Input Name="Project" RecipeArgument="ModuleTestProject" />
    </Action>

  </Actions>
</Recipe>
